package com.ft.sso.secrityauthor2sso.extent;

import org.bouncycastle.crypto.agreement.jpake.JPAKEUtil;
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author RenPu
 * @Date 2022/9/28 18:13
 * @Version 1.0
 * @Description: jwt增强器的编写
 **/
public class JwtExtentConfig implements TokenEnhancer {

    /**
     * 类似后置切面，在通过认证的时候，动态添加响应内容
     * @param accessToken
     * @param authentication
     * @return
     */
    @Override
    public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {

        Map<String, Object> info = new HashMap<>();
        info.put("JwtExtentConfig","JwtExtentConfig is success !!Q!!");  //增强内容信息
        ((DefaultOAuth2AccessToken)accessToken).setAdditionalInformation(info);
        return accessToken;
    }
}
